<template>
    <div>
        <avue-form ref="form" v-model="obj" :option="option"
                   @reset-change="emptytChange"
                   @submit="submit">

        </avue-form>
    </div>
</template>

<script>

import {uploadPath} from "@/config/env";

export default {
    data() {
        return {
            obj: {},
            isIdFind: true,
            initSuccess: false,
        }
    },
    props: {
        uri: {},
        rowData: {},
    },
    computed: {
        option() {
            return {
                // size: "small",
                submitBtn: true,
                emptyBtn: true,
                submitText: '提交',
                emptyText: "关闭",
                column: [
                    {
                        label: '站点Id',
                        prop: 'siteId',
                        labelWidth: 110,
                        maxlength: 32,
                        showWordLimit: true,
                        span: 20,
                        rules: [{
                            required: false,
                            message: "请输入 站点Id",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '站点',
                        prop: 'site',
                        labelWidth: 110,
                        maxlength: 256,
                        showWordLimit: true,
                        span: 20,
                        rules: [{
                            required: false,
                            message: "请输入 站点",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '检查类型',
                        prop: 'type',
                        type: 'radio',
                        labelWidth: 110,
                        dicData: this.dict.get('SITE_CHECK_TYPE'),
                        span: 20,
                        rules: [{
                            required: false,
                            message: "请选择 检查类型",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '检查状态',
                        prop: 'state',
                        type: 'radio',
                        labelWidth: 110,
                        dicData: this.dict.get('VISIT_STATE'),
                        span: 20,
                        rules: [{
                            required: false,
                            message: "请选择 检查状态",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '检查结果',
                        prop: 'result',
                        labelWidth: 110,
                        maxlength: 255,
                        showWordLimit: true,
                        span: 20,
                        rules: [{
                            required: false,
                            message: "请输入 检查结果",
                            trigger: "blur"
                        }]
                    },

                ]
            }
        }
    },
    created() {
        if (this.isIdFind) {
            this.findId(this.rowData);
        } else {
            this.obj = this.rowData;
            this.initSuccess = true;
        }
    },
    methods: {
        emptytChange() {
            this.$emit('closeDialog', false);
        },
        submit(form, done) {
            this.crud.put(this.uri.info + "/" + this.obj.id, this.obj).then((res) => {
                if (res.data.code == 200) {
                    this.$emit('closeDialog', true);
                }
                done(form);
            }).catch(err => {
                console.error(err);
                done(form);
            })
        },
        findId(rowData) {
            if (rowData != null && rowData.id != null) {
                this.crud.get(this.uri.info + "/" + rowData.id).then((res) => {
                    Object.assign(this.obj, res.data.data);
                    this.initSuccess = true;
                })
            }
        }
    }
}
</script>
